package com.corpgovernment.organization.dataloader;

import com.corpgovernment.api.hotelintl.soa.IntlHotelSoaClient;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.common.dto.AllOrderBudgetRequestDto;
import com.corpgovernment.common.dto.AllOrderBudgetResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Slf4j
@Component
public class HotelLintlOrderClientLoader {

    @Autowired
    private IntlHotelSoaClient intlHotelSoaClient;


    public AllOrderBudgetResponseDto getHotelLintlOrderAmount() {
        AllOrderBudgetRequestDto request = new AllOrderBudgetRequestDto();
        request.setFlag(Boolean.FALSE);

        JSONResult<AllOrderBudgetResponseDto> hotelLintlOrderAmount = intlHotelSoaClient.getHotelLintlOrderAmount(request);
        if (hotelLintlOrderAmount == null || hotelLintlOrderAmount.getData() == null) {
            log.warn("查询支付单数据异常:" + Optional.ofNullable(hotelLintlOrderAmount).map(JSONResult::getMsg).orElse("接口无响应"));
            return new AllOrderBudgetResponseDto();
        }
        return hotelLintlOrderAmount.getData();
    }
}
